package com.snail.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snail.mapper.BizQuestionCollectMapper;
import com.snail.service.BizUserQuestionCollectService;
import com.snail.model.pojo.BizUserQuestionCollect;
import com.snail.mapper.BizUserQuestionCollectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
* @author Monica
* @description 针对表【biz_user_question_collect(收藏分类表)】的数据库操作Service实现
* @createDate 2025-07-16 10:22:25
*/
@Service
public class BizUserQuestionCollectServiceImpl extends ServiceImpl<BizUserQuestionCollectMapper, BizUserQuestionCollect>
    implements BizUserQuestionCollectService {
    //查询某一个用户所有的收藏夹
    @Override
    public List<BizUserQuestionCollect> getCollectFoldersByUserId(Integer userId) {
        return this.lambdaQuery()
                .eq(BizUserQuestionCollect::getUserId, userId)
                .orderByDesc(BizUserQuestionCollect::getCreateTime)
                .list();
    }
    //增加收藏夹
    @Override
    public boolean addCollectFolder(String name) {
        //获取用户的id
        int userId= StpUtil.getLoginIdAsInt();
        BizUserQuestionCollect bizUserQuestionCollect = new BizUserQuestionCollect();
        bizUserQuestionCollect.setUserId(userId);
        bizUserQuestionCollect.setTypeName(name);
        //为收藏夹设置唯一id
        String parentId= StpUtil.getLoginIdAsString() ;
        bizUserQuestionCollect.setParentId(parentId);
        bizUserQuestionCollect.setCreateTime(LocalDateTime.now());
        bizUserQuestionCollect.setDeleted(0);
        return this.save(bizUserQuestionCollect);
    }

}




